package com.ha.garbage.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.ha.garbage.R;
import com.ha.garbage.model.Garbage;
import com.ha.garbage.model.GarbageKindVO;

import java.util.ArrayList;
import java.util.List;

public class KindListAdapter extends RecyclerView.Adapter<KindListAdapter.MyHolder>{

    List<GarbageKindVO> garbageKindVOList = new ArrayList<>();

    public KindListAdapter(List<GarbageKindVO> garbageKindVOList) {
        this.garbageKindVOList = garbageKindVOList;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate((R.layout.garbage_item), null);
        return new KindListAdapter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        //绑定数据
        GarbageKindVO garbageKindVO = garbageKindVOList.get(position);
        //设置数据
        holder.tv_introduction.setText("-------");
        holder.tv_kind.setText(garbageKindVO.getKind());
        holder.tv_name.setText("-------");
        String url = garbageKindVO.getImage();
        Glide.with(holder.imageView.getContext()).load(url).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return garbageKindVOList.size();
    }

    static class MyHolder extends RecyclerView.ViewHolder{

        TextView tv_name;
        TextView tv_introduction;
        TextView tv_kind;

        ImageView imageView;

        public MyHolder(@NonNull View itemView) {
            super(itemView);

            //初始化控件
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_kind = itemView.findViewById(R.id.tv_kind);
            tv_introduction = itemView.findViewById(R.id.tv_introduction);
            imageView = itemView.findViewById(R.id.img);

        }
    }
}
